﻿using System;
using NJabber.Client.StanzaFactories;
using NUnit.Framework;

namespace NJabber.Client
{
    [TestFixture]
    public class PresenceStatusStorageTests
    {
        private PresenceStatusStorage presenceStorage;
        private JID entityJid = "amy@lee.com";

        [SetUp]
        public void SetUp()
        {
            presenceStorage = new PresenceStatusStorage();
        }

        [Test]
        public void UpdatePresence_AnyPresenceData_AddsNewPresenceInfo()
        {
            PresenceStatus expectedStatus = new PresenceStatus(entityJid, true, AvailabilityStatus.Chat, "some-description");

            presenceStorage.UpdatePresence(expectedStatus.EntityJid, 
                                           expectedStatus.IsAvailable, 
                                           expectedStatus.AvailabilityStatus, 
                                           expectedStatus.AvailabilityDescription);
            PresenceStatus actualData = presenceStorage[entityJid];

            Assert.That(actualData, Is.EqualTo(expectedStatus));
        }

        [Test]
        [ExpectedException(typeof(ArgumentNullException))]
        public void UpdatePresence_EntityJidNull_ThrowsException()
        {
            presenceStorage.UpdatePresence(null, false);
        }

        [Test]
        public void Indexer_StorageNotContainJid_ReturnsEmptyStatusData()
        {
            PresenceStatus expectedData = new PresenceStatus(entityJid);

            PresenceStatus actualData = presenceStorage[entityJid];

            Assert.That(actualData, Is.EqualTo(expectedData));
        }
    }
}
